package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.Area;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/01/13 14:35
 * @Description:
 */
@Mapper
public interface AreaMapper extends BaseMapper<Area> {
    @Select("select * from area")
    public List<Area> findAllArea();

    @Update("update `area` set `create_time`=#{createTime}, `update_time`=#{updateTime} ")
    public Integer updateAllAreaTime(@Param("createTime") Long createTime, @Param("updateTime") Long updateTime);

    //找出所有省级地域
    @Select("select * from `area` where `city_level`= 2")
    public List<Area> findAllProvinces();

    //找出所有市级地域
    @Select("select * from `area` where `city_level`= 3")
    public List<Area> findAllCities();

    //找出所有县级地域
    @Select("select * from `area` where `city_level`= 4")
    public List<Area> findAllCountries();

    @Select("select * from `area` where `parent_id`=#{parentId}")
    public List<Area> findCityLevelByParentId(@Param("parentId") Integer parentId);

    @Select("select * from `area` where `parent_id`=#{parentId}")
    public List<Area> findCountryLevelByParentId(@Param("parentId") Integer parentId);

    @Select("select `city_name` from `area` where `id`=#{id}")
    public String findCityNameById(@Param("id") Integer id);

    @Select("select `parent_id` from `area` where `id`=#{id}")
    public Integer findParentIdById(@Param("id") Integer id);

    //找出某省级下的所有市级和县级地域
    @Select("select * from `area` where `parent_id`=#{area.id} and `city_level`=3")
    public List<Area> findCitiesAndCountries(@Param("area") Area area);

    @Select("select id from area where city_name=#{cityName}")
    public Integer findAreaIdByName(@Param("cityName") String cityName);

    @Select("select * from area where city_level=3 and city_name='市辖区'")
    public List<Area> findCitySpecial();
}
